package LinkList;

import java.util.ArrayList;
import java.util.Arrays;

public class Test {
    //将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
    public static  MySingleList.ListNode mergeTwoLists(MySingleList.ListNode headA, MySingleList.ListNode headB) {
        MySingleList.ListNode newHead =new MySingleList.ListNode(-1);
        MySingleList.ListNode tmp =newHead;
        while(headA !=null && headB !=null){
            if(headA.val<headB.val){
                tmp.next =headA;
                headA =headA.next;
                tmp =tmp.next;
            }else{
                tmp.next =headB;
                headB =headB.next;
                tmp =tmp.next;
            }
        }
        if(headA !=null){
            tmp.next =headA;
        }
        if(headB !=null){
            tmp.next =headB;
        }
        return newHead;
    }

    public static void main3(String[] args) {
        MySingleList list1 =new MySingleList();
        list1.addLast(11);
        list1.addLast(22);
        list1.addLast(31);
        list1.addLast(41);
        list1.addLast(51);
        MySingleList list2 = new MySingleList();
        list2.addLast(12);
        list2.addLast(24);
        list2.addLast(35);
        list2.addLast(45);
        list2.addLast(56);
       MySingleList.ListNode newH =mergeTwoLists(list1.head,list2.head);
       list2.display2(newH);

    }

    public static void main2(String[] args) {
        MySingleList list =new MySingleList();
        list.addFirst(1);
        list.addFirst(21);
        list.addFirst(32);
        list.addFirst(45);
        list.addFirst(56);
        list.addLast(99);
        list.addLast(77);
        list.addIndex(3,66);
        list.addIndex(1,85);
        list.display();
        int len = list.size();
        System.out.println(len);
    }
    public static void main1(String[] args) {
        MySingleList list =new MySingleList();
        list.createList();
//        list.display();
        list.addFirst(99);
        list.addLast(111);
        list.addIndex(0,109);
        list.display();
    }
}
